package com.jiyun.controller;

import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import com.alibaba.nacos.common.utils.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jiyun.pojo.JsonRes;
import com.jiyun.pojo.Managesell;
import com.jiyun.service.ManagesellService;
import com.jiyun.utils.AliyunOSSClientUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.commons.util.IdUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author: 刘清芳
 * @description: 出售商品
 * @date: 2023/12/24 19:12
 */
@RestController
@RequestMapping("managesell")
public class ManageSellController {
    @Autowired
    ManagesellService managesellService;
//    展示
    @RequestMapping("/findAllManagesell")
    public Page<Managesell>findAllManagesell(@RequestBody Managesell manageSell, @RequestParam Integer pageNum, @RequestParam Integer pageSize){
        return managesellService.findAllManagesell(manageSell,pageNum,pageSize);
    }

    //    上传图片
    @PostMapping("/fileUpload")
    public JsonRes fileUpload(MultipartFile file) {
        AliyunOSSClientUtil aliyunOSSClientUtil = new AliyunOSSClientUtil();
        try {
            String s = aliyunOSSClientUtil.uploadImg2Oss(file);
            String imgUrl = aliyunOSSClientUtil.getImgUrl(s);
            return JsonRes.success(imgUrl);
        } catch (Exception e) {
            e.printStackTrace();
            return JsonRes.error("上传失败");
        }
    }

    //    添加
    @PostMapping("/findAdd")
    public void findAdd(@RequestBody Managesell managesell){
        managesell.setSpsel(25.26);
        managesell.setXiaol(25);
        managesell.setKuc(25);
        managesell.setPaix(25);
        managesellService.saveOrUpdate(managesell);
    }
}
